<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Cluster state API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'cluster-state.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/cluster-state.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/cluster-state.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/cluster-state.html" rel="nofollow" target="_blank">../en/cluster-state.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="cluster.html">Cluster APIs</a></span>
»
<span class="breadcrumb-node">Cluster state API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="cluster-reroute.html">« Cluster reroute API</a>
</span>
<span class="next">
<a href="cluster-stats.html">Cluster stats API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="cluster-state"></a>Cluster state API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cluster/state.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Returns metadata about the state of the cluster.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cluster-state-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cluster/state.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">GET /_cluster/state/&lt;metrics&gt;/&lt;index&gt;</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cluster-state-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cluster/state.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The cluster state API allows access to metadata representing the state of the
whole cluster. This includes information such as</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
the set of nodes in the cluster
</li>
<li class="listitem">
all cluster-level settings
</li>
<li class="listitem">
information about the indices in the cluster, including their mappings and
settings
</li>
<li class="listitem">
the locations of all the shards in the cluster.
</li>
</ul>
</div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>The response is an internal representation of the cluster state and its
format may change from version to version. If possible, you should obtain any
information from the cluster state using the other, more stable,
<a class="xref" href="cluster.html" title="Cluster APIs">cluster APIs</a>.</p>
</div>
</div>
<p>The response provides the cluster state itself, which can be filtered to only
retrieve the parts of interest as described below.</p>
<p>The cluster’s <code class="literal">cluster_uuid</code> is also returned as part of the top-level response,
in addition to the <code class="literal">metadata</code> section. <span class="Admonishment Admonishment--change">
[<span class="Admonishment-version u-mono">6.4.0</span>]
<span class="Admonishment-detail">
Added in 6.4.0.
</span>
</span></p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>While the cluster is still forming, it is possible for the <code class="literal">cluster_uuid</code>
      to be <code class="literal">_na_</code> as well as the cluster state’s version to be <code class="literal">-1</code>.</p>
</div>
</div>
<p>By default, the cluster state request is routed to the master node, to ensure
that the latest cluster state is returned. For debugging purposes, you can
retrieve the cluster state local to a particular node by adding <code class="literal">local=true</code> to
the query string.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cluster-state-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cluster/state.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The cluster state contains information about all the indices in the cluster,
including their mappings, as well as templates and other metadata. This means it
can sometimes be quite large. To avoid the need to process all this information
you can request only the part of the cluster state that you need:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;metrics&gt;</code>
</span>
</dt>
<dd>
<p>
(Optional, string) A comma-separated list of the following options:
</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">_all</code>
</span>
</dt>
<dd>
Shows all metrics.
</dd>
<dt>
<span class="term">
<code class="literal">blocks</code>
</span>
</dt>
<dd>
Shows the <code class="literal">blocks</code> part of the response.
</dd>
<dt>
<span class="term">
<code class="literal">master_node</code>
</span>
</dt>
<dd>
Shows the elected <code class="literal">master_node</code> part of the response.
</dd>
<dt>
<span class="term">
<code class="literal">metadata</code>
</span>
</dt>
<dd>
Shows the <code class="literal">metadata</code> part of the response. If you supply a comma separated
list of indices, the returned output will only contain metadata for these
indices.
</dd>
<dt>
<span class="term">
<code class="literal">nodes</code>
</span>
</dt>
<dd>
Shows the <code class="literal">nodes</code> part of the response.
</dd>
<dt>
<span class="term">
<code class="literal">routing_nodes</code>
</span>
</dt>
<dd>
Shows the <code class="literal">routing_nodes</code> part of the response.
</dd>
<dt>
<span class="term">
<code class="literal">routing_table</code>
</span>
</dt>
<dd>
Shows the <code class="literal">routing_table</code> part of the response. If you supply a comma
separated list of indices, the returned output will only contain the
routing table for these indices.
</dd>
<dt>
<span class="term">
<code class="literal">version</code>
</span>
</dt>
<dd>
Shows the cluster state version.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
(Optional, string) Comma-separated list or wildcard expression of index names
used to limit the request.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cluster-state-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cluster/state.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">allow_no_indices</code>
</span>
</dt>
<dd>
<p>
(Optional, boolean) If <code class="literal">true</code>, the wildcard indices expression that resolves
into no concrete indices will be ignored. (This includes <code class="literal">_all</code> string or
when no indices have been specified).
</p>
<p>Defaults to <code class="literal">true</code>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">expand_wildcards</code>
</span>
</dt>
<dd>
(Optional, string) Whether to expand wildcard expression to concrete indices
that are open, closed or both. Available options: <code class="literal">open</code>, <code class="literal">closed</code>, <code class="literal">none</code>,
<code class="literal">all</code>.
</dd>
<dt>
<span class="term">
<code class="literal">flat_settings</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, returns settings in flat format. Defaults to
<code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">ignore_unavailable</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, unavailable indices (missing or closed) will
be ignored.
</dd>
<dt>
<span class="term">
<code class="literal">local</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, the request retrieves information from the local
node only. Defaults to <code class="literal">false</code>, which means information is retrieved from
the master node.
</dd>
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">wait_for_metadata_version</code>
</span>
</dt>
<dd>
(Optional, integer) Waits for the metadata version to be equal or greater
than the specified metadata version.
</dd>
<dt>
<span class="term">
<code class="literal">wait_for_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the maximum time to wait
for wait_for_metadata_version before timing out.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cluster-state-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cluster/state.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The following example returns only <code class="literal">metadata</code> and <code class="literal">routing_table</code> data for the
<code class="literal">foo</code> and <code class="literal">bar</code> indices:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_cluster/state/metadata,routing_table/foo,bar</pre>
</div>
<div class="console_widget" data-snippet="snippets/1393.console"></div>
<p>The next example returns everything for the <code class="literal">foo</code> and <code class="literal">bar</code> indices:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_cluster/state/_all/foo,bar</pre>
</div>
<div class="console_widget" data-snippet="snippets/1394.console"></div>
<p>This example returns only the <code class="literal">blocks</code> metadata:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_cluster/state/blocks</pre>
</div>
<div class="console_widget" data-snippet="snippets/1395.console"></div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="cluster-reroute.html">« Cluster reroute API</a>
</span>
<span class="next">
<a href="cluster-stats.html">Cluster stats API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>